﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 三国杀
{
    public partial class GameMain : Form
    {
        public GameMain()
        {
            InitializeComponent();
            this.MouseDown += GameMain_MouseDown;
            this.MouseUp += GameMain_MouseUp;
            this.MouseMove += GameMain_MouseMove;
        }

        Point mousePosition;

        Point formPosition;

        bool isMouseDown = false;//是否按下


        private void GameMain_MouseDown(object sender, MouseEventArgs e)
        {
            isMouseDown = true;

            mousePosition = Control.MousePosition;  //鼠标位置

            formPosition = this.Location;   //窗体左上角位置
        }

        private void GameMain_MouseUp(object sender, MouseEventArgs e)
        {
            isMouseDown = false;
        }

        private void GameMain_MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePoint = Control.MousePosition;   //移动的位置
            if (isMouseDown)
            {
                this.Location = new Point(mousePoint.X - mousePosition.X + formPosition.X, mousePoint.Y - mousePosition.Y + formPosition.Y);
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.Opacity = 0;
        }

        double num;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (num <= 1) {
                num += 0.1;
            }
            this.Opacity = num;
        }

   

        private void timer2_Tick(object sender, EventArgs e)
        {
            //if (this.pictureBox1.Location.Y > this.pictureBox2.Location.Y)
            //{
            //    this.pictureBox2.Top += 10;
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //this.timer2.Enabled = true;
        }

        private void pb3_Click(object sender, EventArgs e)
        {
            //至尊场人机对战入口
            new pvp().Show();
        }
        
        private void pb4_Click(object sender, EventArgs e)
        {
            // 自由场人机对战入口
            string exePath = ConfigurationManager.AppSettings["ExePath"]; // 配置文件读取路径


            try
            {
                var startInfo = new ProcessStartInfo
                {
                    FileName = exePath,
                    UseShellExecute = true,
                    WorkingDirectory = Path.GetDirectoryName(exePath) // 设置工作目录
                };

                Process.Start(startInfo);
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("找不到人机对战程序，请检查路径配置！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"启动失败：{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
